<template>
  <div>
    <div style="font-size:18px;margin-bottom: 15px;">
      <a href="#" @click="prev" style="text-decoration:none;font-size: 14px;">
        <icon-svg name="jiantou" style="width: 1.2em;height: 1.2em;position: relative;top: 0.3em;"></icon-svg>
        返回
      </a>
      <span style="display: inline-block;margin: 0 15px;color: #D9D9D9;">|</span>
      <span>评价明细</span>
    </div>

    <div style="margin:2% 0;display: inline-block;">
     <div style="position: relative;display: inline-block;margin: 10px 0px;">
       <span>筛选类型：</span>
       <el-select v-model="grade" style="width:150px;margin-left: 10px;" @change="animeDat2(grade)">
         <el-option v-for="item in scoreTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
       </el-select>&nbsp;&nbsp;&nbsp;
     </div>
     <el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="dataSelect">查询
     </el-button>
     <el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="cleans2">重置</el-button>
    </div>
    <el-table v-loading="tableDataLoading" :data="tableData.list">
      <el-table-column fixed prop="id" label="编号" width="80">
      </el-table-column>
      <!-- <el-table-column prop = "nickName" label = "用户昵称" width = "120">
      	<template slot-scope="scope">
      		<div style="color: #4f9dec;cursor: pointer;" @click="updates(scope.row)">{{scope.row.nickName?scope.row.nickName:'未绑定'}}</div>
      	</template>
      </el-table-column> -->
      <el-table-column prop="avatar" label="用户头像" width="100">
        <template slot-scope="scope">
          <div style="display: inline-block; margin: 3px;">
            <el-popover placement="top-start" title="" trigger="hover">
              <img style="width: 50px; height: 50px" :src="scope.row.avatar" alt="" slot="reference">
              <img style="width: 300px; height: auto" :src="scope.row.avatar" alt="">
            </el-popover>
          </div>

        </template>
      </el-table-column>

      <el-table-column prop="nickName" label="用户" width="150">
        <template slot-scope="scope">
          <span style="color: #4f9dec;cursor: pointer;" @click='goUserInfo(scope.row.userId)'>{{scope.row.nickName ? scope.row.nickName : '暂无'}}</span>
        </template>
      </el-table-column>

      <el-table-column prop="orderNumber" label="订单号">
      </el-table-column>
      <el-table-column prop="score" label="评分" width="80">
      </el-table-column>
<!--      <el-table-column prop="image" label="评价图" width="100">
        <template slot-scope="scope">
          <div style="display: inline-block; margin: 3px;">
            <el-popover v-if="scope.row&&scope.row.newImage" placement="top-start" title="" trigger="hover" v-for="item in scope.row.newImage" :key="item">
              <img style="width: 50px; height: 50px" :src="item" alt="" slot="reference">
              <img style="width: 300px; height: auto" :src="item" alt="">
            </el-popover>
          </div>

        </template>
      </el-table-column> -->
      <el-table-column prop="evaluateMessage" label="评价内容">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="" trigger="hover">
            <div style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;max-height:80px;" slot="reference">{{scope.row.evaluateMessage}}</div>
            <div style="width: 400px;">{{scope.row.evaluateMessage}}</div>
          </el-popover>
        </template>
      </el-table-column>
			<el-table-column prop="evaluateMessage" label="评论图片" width="280">
			  <template slot-scope="scope">
			  	<div v-if="scope.row.pictures">
			  		<span v-for="(item,index) in scope.row.pictures.split(',')" :key="index">
			  			<el-popover placement="top-start" title="" trigger="hover">
			  				<img style="width: 50px; height: 50px;margin: 3px;" :src="item" alt="" slot="reference">
			  				<img style="width: 200px; height: 200px" :src="item" alt="">
			  			</el-popover>
			  		</span>
			  	</div>
			  </template>
			</el-table-column>
      <el-table-column prop="createTime" label="时间" width="150">
      </el-table-column>
      <el-table-column prop="shopReplyMessage" label="商家回复内容">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="" trigger="hover">
            <div style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;max-height:80px;" slot="reference">{{scope.row.shopReplyMessage}}</div>
            <div style="width: 400px;">{{scope.row.shopReplyMessage}}</div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="ordersPayMoney" label="操作" width="80">
      	<template slot-scope="scope">
      		<el-button size="mini" :disabled="!isAuth('shopsList:deletePl')" type="warning" icon="document" @click="deleteBtn(scope.row)">删除</el-button>
      	</template>
      </el-table-column>
    </el-table>
    <div style="text-align: center;margin-top: 10px;">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30, 40,100]" :page-size="limit" :current-page="page" layout="total,sizes, prev, pager, next"
        :total="tableData.totalCount">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        limit: 10,
        page: 1,
        activeName: 'first',
        tableDataLoading: false,
        grade:'',
        dialogFormVisible: false,
        tableData: {},
        scoreTypes: [{//后台定义 1 2差评 3 4中评 5是好评
            label: '全部',
            value: ''
          },
          {
            label: '好评',
            value: 1
          },
          {
            label: '中评',
            value: 2
          },
          {
            label: '差评',
            value: 3
          },
        ],
        shopId:'',
      }
    },
    methods: {
      //提交查询
      animeDat2(state) {
        this.page = 1
        this.grade=state;
        this.dataSelect()
      },

      cleans2(){
        this.page = 1
        this.grade='';
        this.dataSelect()
      },

      //查看用户详情
      goUserInfo(userId){
        this.$router.push({
          path: '/userDetail',
          query: {
            userId
          }
        })

      },

      handleSizeChange(val) {
        this.limit = val;
        this.dataSelect()
      },
      handleCurrentChange(val) {
        this.page = val;
        this.dataSelect()
      },

      // 获取派单数据列表
      dataSelect() {
        this.tableDataLoading = true
        this.$http({
          url: this.$http.adornUrl('app/goods/selectEvaluateByShopId'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.page,
            'limit': this.limit,
            'shopId': this.shopId,
            'grade':this.grade,
          })
        }).then(({
          data
        }) => {
          this.tableDataLoading = false
          let returnData = data.data.pageUtils;

          for (var i = 0; i < returnData.list.length; i++) {
            if(returnData.list[0].image){
              returnData.list[0].newImage=returnData.list[0].image.split(',')
            }
          }

          this.tableData = returnData

        })
      },
      // 返回上一级
      prev() {
        this.$router.back()
      },
      // 删除评论
      deleteBtn(row){
        this.$confirm(`确定要删除评论吗?`, '提示', {
        	confirmButtonText: '确定',
        	cancelButtonText: '取消',
        	type: 'warning'
        }).then(() => {
        	this.$http({
        		url: this.$http.adornUrl('admin/order/deleteEvaluate'),
        		method: 'post',
        		params: this.$http.adornParams({
        			'evaluateId': row.id
        		})
        	}).then(({
        		data
        	}) => {
        		if(data.code==0){
        			this.$message({
        				message: '取消成功',
        				type: 'success',
        				duration: 1500,
        				onClose: () => {
        					this.dataSelect()
        				}
        			})
        		}else{
        			this.$message({
        				message: data.msg,
        				type: 'warning',
        				duration: 1500,
        				onClose: () => {
        				}
        			})
        		}

        	})
        }).catch(() => {})
      },
    },
    mounted() {
      this.shopId = this.$route.query.shopId
      this.dataSelect()
    }
  };
</script>

<style>

</style>
